package com.zilu.digitaltwin.common.exception;


/**
 * @author :caijianbao
 * @date : 2023/1/2 22:29
 */
public enum CommonErrorCode implements ICommonErrorCode {

    UNKNOWN_ERROR(0, 200, "未知错误"),
    SERVER_ERROR(1, 200, "服务器错误"),
    INPUT_NOT_VALID(2, 200, "输入出错"),
    UPDATE_FAIL(4, 200, "更新错误"),
    SAVE_ERROR(5, 200, "新增错误"),
    REQUEST_ARGUMENTS_ERROR(3, 200, "请求参数错误"),
    DB_ERROR(7, 200, "数据库操作错误"),
    CHANGE_CHECK_NOT_VALID(8, 200, "修改校验失败"),
    CONFIGURATION_EXCEPTION(9, 200, "配置异常"),
    FORBIDDEN_EXCEPTION(10, 403, "没有权限"),
    NOT_FOUND_TASK_TYPE(11, 200, "没有对应的任务类型！"),
    UNKNOWN_DATA_STORE_TYPE(12, 200, "未知的存储类型！"),
    DELETE_FAIL(14, 200, "删除错误"),
    PARAMETER_ERROR(20, 200, "参数错误"),
    TABLE_NOT_EXIST(30, 200, "数据库表不存在"),
    TABLE_INDEX_NOT_EXIST(31, 200, "数据库索引不存在"),
    PARSER_NOT_EXISTS(20, 200, "解析器不存在"),
    PARSER_EXCEPTION(21, 200, "解析异常"),
    EXPORT_EXCEPTION(22, 200, "导出异常"),
    IMPORT_EXCEPTION(23, 200, "导入异常"),
    FILE_NOT_FOUND(24, 200, "文件找不到");

    private Integer statusCode;

    private Integer codeNumber;

    private String message;

    private String code;

    @Override
    public Integer getStatusCode() {
        return this.statusCode;
    }

    @Override
    public Integer getCodeNumber() {
        return this.codeNumber;
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    @Override
    public String getCode() {
        return this.code;
    }

    private CommonErrorCode(Integer codeNumber, Integer statusCode, String message) {
        this.codeNumber = codeNumber;
        this.statusCode = statusCode;
        this.message = message;
        this.code = this.name();
    }

    public static CommonErrorCode getCommonErrorCode(Integer codeNumber) throws Exception {
        for (CommonErrorCode errorCode : values()) {
            if (errorCode.getCodeNumber().equals(codeNumber)) {
                return errorCode;
            }
        }
        throw new Exception("cannot match errorCode by " + codeNumber);
    }


}
